home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
Monster Media 1994 #2
/
Monster Media No. 2 (Monster Media)(1994).ISO
/
prog_gen
/
psp_io.zip
/
DOSIO.ASM
< prev
next >
Wrap
Assembly Source File
|
1994-05-28
|
8KB
|
203 lines
;****************************************************************************
; I O D O S . A S M
;============================================================================
; Input and output routines using DOS interrupts and functions.
;---------------------------------------------------------------------------
; Copyright (c) Simon Groes, 1994
;---------------------------------------------------------------------------
; Assemble with Borland Turbo Assembler v3.0
;****************************************************************************
IDEAL
DOSSEG
MODEL small
LOCALS
;----- Insert INCLUDE "filename" directives here
INCLUDE "macro.inc"
INCLUDE "common.inc"
;----- Insert EQU and = equates here
BufSize = 0FFh ; Maximum string size (<=255).
STRUC StrBuffer
maxLength db BufSize ; Maximum buffer length.
strLength db 0 ; Length of actual string in buffer.
theString db BufSize DUP (0) ; The string of chars.
ENDS StrBuffer
DATASEG
dosBuffer StrBuffer <> ; For dosGetStr
;----- Specify any EXTRN variables here
CODESEG
EXTRN strLength:proc, strCopy:proc
;----- Declare PUBLIC procedures here
PUBLIC dosPutString, dosKeyPress, dosGetRawChar, dosPutChar
PUBLIC dosGetString, dosNewLine, dosGetEchoChar
;===============================================================
; Procedure: =*=dosPutString=*=
;---------------------------------------------------------------
; Usage: Public - May be used in this & other asm files.
; Task: Write string to screen using DOS function 40h of int 21h.
; Input: di = offset address of string.
; Output: String written to screen (handle 1: std output device).
; Registers: none
;===============================================================
PROC dosPutString
SaveRegs <ax, bx, cx, dx>
call strLength ; Length of string in cx.
mov dx, di ; Offset should be in dx.
mov bx, HANDLE_1 ; Handle #1 (screen).
Function 40h ; Function 40 in ah.
DOS_21H ; Call int 21h.
RestoreRegs <dx, cx, bx, ax>
ret
ENDP dosPutString
;===============================================================
; Procedure: =*=dosKeyPress=*=
;---------------------------------------------------------------
; Task: Wait for key press.
; Input: none
; Output: none
; Registers: none
; Note: Unfiltered input means special input such as CTRL+C
; are not interpreted to instructions.
; Function 07h reads char from keyboard input buffer.
; If empty, waits for keypress. Char read is in al.
;===============================================================
PROC dosKeyPress
SaveRegs <ax>
Function 07h ; Read unfiltered char. Char in al.
DOS_21H ; Call dos int 21h.
RestoreRegs <ax>
ret
ENDP dosKeyPress
;===============================================================
; Procedure: =*=dosGetRawChar=*=
;---------------------------------------------------------------
; Task: Get unfiltered character from keyboard,
; if none available, wait for keypress.
; Input: none
; Output: al = ASCII value of character.
; Registers: ax changed.
; Note: Unfiltered input means special input such as CTRL+C
; are not interpreted to instructions.
; Function 07h reads char from keyboard input buffer.
; If empty, waits for keypress. Char read is in al.
;===============================================================
PROC dosGetRawChar
Function 07h ; Read unfiltered char. Char in al.
DOS_21H ; Call dos interrupt 21h.
xor ah, ah ; Clear ah register.
ret ; Return to caller.
ENDP dosGetRawChar
;===============================================================
; Procedure: =*=dosPutChar=*=
;---------------------------------------------------------------
; Task: Display filtered character on screen.
; Input: al = character to be displayed.
; Output: none
; Registers: ax changed.
; Note: Filtered means special characters such as
; CTRL+C, CTRL+S, Return etc are treated as
; system control keys an not mere ASCII values.
;===============================================================
PROC dosPutChar
SaveRegs <dx>
mov dl, al ; Dos function requires char in dl.
Function 02h ; Filtered character output.
DOS_21H ; Call dos interrupt 21h.
RestoreRegs <dx>
ret ; Return to caller.
ENDP dosPutChar
;===============================================================
; Procedure: =*dosGetEchoChar=*=
;---------------------------------------------------------------
; Task: Get char input from keyboard buffer and echo to screen.
; Input: none
; Output: al = character read.
; Registers: ax changed.
; Note: Recognises ASCII control codes.
; If no char in buffer, function waits until one
; is available.
;===============================================================
PROC dosGetEchoChar
Function 01h ; Character input with echo.
DOS_21H ; Call dos interrupt 21h.
xor ah, ah ; Clear ah.
ret
ENDP dosGetEchoChar
;===============================================================
; Procedure: =*=dosGetString=*=
;---------------------------------------------------------------
; Task: Get string (buffered input) from keyboard, and
; store in buffer.
; Input: di = Address of buffer to hold string.
; cl = Maximum string length (excluding NULL).
; Output: String copied from standard input (keyboard) to buffer.
; Registers: none
; Note: Character input ends when user presses <enter>.
; Max # of chars includes <enter>.
;===============================================================
PROC dosGetString
or cl, cl ; Value in cl ?
jz @@Return ; No: End routine.
SaveRegs <ax,bx,dx,si>
mov [dosBuffer.maxLength], cl ; Max length in 1st byte.
mov dx, OFFSET dosBuffer.maxLength ; dx -> dosBuffer.
Function 0Ah ; Buffered-Input.
DOS_21H ; Call dos int 21h.
mov si, OFFSET dosBuffer.theString ; si -> string.
xor bh,bh ; Clear bh.
mov bl, [dosBuffer.strLength] ; bl = string length - <rtn>.
mov [BYTE bx+si], NULL ; Replace <enter> with NULL.
call strCopy ; Copy string to [di].
@@Return:
RestoreRegs <si,dx,bx,ax>
ret ; Return to caller.
ENDP dosGetString
;===============================================================
; Procedure: =*=dosNewLine=*=
;---------------------------------------------------------------
; Task: Move cursor to the beginning of the next line.
; Input: none
; Output: none
; Registers: none
;===============================================================
PROC dosNewLine
SaveRegs<ax,dx>
Function 02h
mov dl, LF ; Move to next line.
DOS_21H
mov dl, CR ; Move to beginning of line.
DOS_21H
RestoreRegs<dx,ax>
ret ; Return to caller.
ENDP dosNewLine
END ; End of routines.